import type { App } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersist from 'pinia-plugin-persist'

const store = createPinia()

store.use(piniaPluginPersist)

export const setupStore = (app: App<Element>) => {
  app.use(store)
}

export { store }

const modulesFiles: any = import.meta.glob('./modules/*.ts', { eager: true })
const modules: any = {}

for (const key in modulesFiles) {
  for (const item in modulesFiles[key]) {
    modules[item] = modulesFiles[key][item]
  }
}

export const useStore = modules
